<template>
  <div class="row justify-content-center">
    <div class="col-8">
      <form name="editForm" role="form" novalidate v-on:submit.prevent="save()">
        <h2 id="application4App.student.home.createOrEditLabel" data-cy="StudentCreateUpdateHeading">Create or edit a Student</h2>
        <div>
          <div class="form-group" v-if="student.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id" v-model="student.id" readonly />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-studentNumber">Student Number</label>
            <input
              type="text"
              class="form-control"
              name="studentNumber"
              id="student-studentNumber"
              data-cy="studentNumber"
              :class="{ valid: !$v.student.studentNumber.$invalid, invalid: $v.student.studentNumber.$invalid }"
              v-model="$v.student.studentNumber.$model"
              required
            />
            <div v-if="$v.student.studentNumber.$anyDirty && $v.student.studentNumber.$invalid">
              <small class="form-text text-danger" v-if="!$v.student.studentNumber.required"> This field is required. </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-studentName">Student Name</label>
            <input
              type="text"
              class="form-control"
              name="studentName"
              id="student-studentName"
              data-cy="studentName"
              :class="{ valid: !$v.student.studentName.$invalid, invalid: $v.student.studentName.$invalid }"
              v-model="$v.student.studentName.$model"
            />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-studentStatus">Student Status</label>
            <input
              type="number"
              class="form-control"
              name="studentStatus"
              id="student-studentStatus"
              data-cy="studentStatus"
              :class="{ valid: !$v.student.studentStatus.$invalid, invalid: $v.student.studentStatus.$invalid }"
              v-model.number="$v.student.studentStatus.$model"
            />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-studentPassword">Student Password</label>
            <input
              type="text"
              class="form-control"
              name="studentPassword"
              id="student-studentPassword"
              data-cy="studentPassword"
              :class="{ valid: !$v.student.studentPassword.$invalid, invalid: $v.student.studentPassword.$invalid }"
              v-model="$v.student.studentPassword.$model"
              required
            />
            <div v-if="$v.student.studentPassword.$anyDirty && $v.student.studentPassword.$invalid">
              <small class="form-text text-danger" v-if="!$v.student.studentPassword.required"> This field is required. </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-studentSex">Student Sex</label>
            <select
              class="form-control"
              name="studentSex"
              :class="{ valid: !$v.student.studentSex.$invalid, invalid: $v.student.studentSex.$invalid }"
              v-model="$v.student.studentSex.$model"
              id="student-studentSex"
              data-cy="studentSex"
            >
              <option v-for="sex in sexValues" :key="sex" v-bind:value="sex">{{ sex }}</option>
            </select>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="student-address">Address</label>
            <input
              type="text"
              class="form-control"
              name="address"
              id="student-address"
              data-cy="address"
              :class="{ valid: !$v.student.address.$invalid, invalid: $v.student.address.$invalid }"
              v-model="$v.student.address.$model"
            />
          </div>
          <div class="form-group">
            <label for="student-userClass">User Class</label>
            <select
              class="form-control"
              id="student-userClasses"
              data-cy="userClass"
              multiple
              name="userClass"
              v-if="student.userClasses !== undefined"
              v-model="student.userClasses"
            >
              <option
                v-bind:value="getSelected(student.userClasses, userClassOption)"
                v-for="userClassOption in userClasses"
                :key="userClassOption.id"
              >
                {{ userClassOption.id }}
              </option>
            </select>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" v-on:click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>Cancel</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="$v.student.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>Save</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./student-update.component.ts"></script>
